﻿using MyHospital.DAL;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace MyHospital.BLL
{
    public class Disease
    {
        MyHospitalDataContext db = new MyHospitalDataContext();
        public bool isDiseaseExit(string name)//确认疾病是否已存在
        {
            DAL.Disease disease = (from c in db.Disease
                                   where c.disName == name
                                   select c).FirstOrDefault();
            if (disease == null) return true;
            else return false;
        }
        public void insertDisease(int departID,string name)//插入疾病
        {
            DAL.Disease disease = new DAL.Disease();
            disease.departId = departID;
            disease.disName = name;
            db.Disease.InsertOnSubmit(disease);
            db.SubmitChanges();
        }
        public void deleteDisease(string id)//删除一条疾病
        {
            DAL.Disease disease = (from c in db.Disease
                                   where c.disId == int.Parse(id)
                                   select c).FirstOrDefault();
            db.Disease.DeleteOnSubmit(disease);
            db.SubmitChanges();
        }
        public void deleteAllDisease(string name)//删除多条疾病
        {
            var disease = (from c in db.Disease
                                   where c.disName == name
                                   select c);
            db.Disease.DeleteAllOnSubmit(disease);
            db.SubmitChanges();
        }
        public IQueryable<int?> searchDepart(string name)//查找某疾病出现的部门
        {
            var depart = (from c in db.Disease
                          where c.disName == name
                          select c.departId);
            return depart;
        }
    }
}
